/*
 * @Author: hongbin
 * @Date: 2022-09-27 20:16:10
 * @LastEditors: hongbin
 * @LastEditTime: 2022-09-27 22:19:36
 * @Description:多scene渲染
 */
import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";

export const init = (params: THREE.WebGLRendererParameters) => {
    const renderer = new THREE.WebGLRenderer(params);
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.shadowMap.enabled = true;
    renderer.outputEncoding = THREE.sRGBEncoding;

    const camera = new THREE.PerspectiveCamera(
        75,
        window.innerWidth / window.innerHeight,
        0.1,
        500
    );
    camera.position.set(2, 6, 4);
    const controls = new OrbitControls(camera, renderer.domElement);

    camera.position.set(2, 6, 4);
    const controls2 = new OrbitControls(camera, renderer.domElement);

    // renderer.setAnimationLoop(render);

    controls.addEventListener("change", render);
    controls2.addEventListener("change", render);

    function render() {
        renderer.render(scene, camera);
        //下面的会覆盖上面的
        renderer.render(scene2, camera);
    }

    const scene = new THREE.Scene();
    const scene2 = new THREE.Scene();

    // scene.add(new THREE.AxesHelper(4));
    scene2.add(new THREE.AxesHelper(7));
    // scene2.background = new THREE.Color("transparent");
    // scene2.background = new THREE.Color("#901");
    renderer.setClearAlpha(0);
    const m = new THREE.Mesh(
        new THREE.BoxGeometry(4, 6, 1),
        new THREE.MeshBasicMaterial({ color: 0x5511ff, side: 2 })
    );

    scene.add(m);

    // scene2.position.set(1, 1, 1);
    // scene2.scale.set(0.2, 0.2, 0.2);
    // scene2.position.set(2, 2, 2);

    scene.add(scene2);

    render();
};
